/*
 * Copyright (c) 2006 DSS Dev. Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the DSS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      NodeStorage.hpp
 *
 * $DSS$
 */
#ifndef _NODE_STORAGE_HPP__
#define _NODE_STORAGE_HPP__ 1

#include <Types.h>

namespace FTSS // FullTextSearchSystem
{

typedef UINT_64 BTreeNodeID_t;
typedef INT_32 Result_t;
typedef INT_32 KeySize_t;
typedef INT_32 LockMode_t;
typedef INT_32 Level_t;
/**
  @class NodeStorage BTree.hpp <BTree.hpp>
  @brief Pure abstract class
*/
template <typename T>class NodeStorage
{
public:
	/**
	  @brief Create node storage
	  @param iMaxNodesCount - maximum nodes count
	*/
	virtual Result_t CreateStorage(KeySize_t iMaxNodesCount)                      throw() = 0;

	/**
	  @brief Set current root node ID
	  @param iNodeID - root node id
	*/
	virtual void SetRootNodeId(const BTreeNodeID_t & iNodeID)                     throw() = 0;

	/**
	  @brief Get current root node ID
	  @return Current root node id
	*/
	virtual BTreeNodeID_t GetRootNodeId() const                                   throw() = 0;

	/**
	  @brief Create a new B-Tree node and lock it
	  @param iNodeID - Node ID
	  @return pointer to tree node or NULL if node does not exist
	*/
	virtual T * CreateAndLock(BTreeNodeID_t & iNodeID)                            throw() = 0;

	/**
	  @brief Get and lock existing node
	  @param iNodeID - Node ID
	  @param iLockMode - lock mode
	  @return pointer to tree node or NULL if node does not exist
	*/
	virtual T * GetAndLock(const BTreeNodeID_t & iNodeID, LockMode_t iLockMode)   throw() = 0;

	/**
	  @brief Unlock node
	  @param iNodeID - Node ID
	  @return 0 uif success, -1 if node does not exist or any error occured
	*/
	virtual Result_t Unlock(const BTreeNodeID_t & iNodeID)                        throw() = 0;

	/**
	  @brief Destroy Node
	  @param iNodeID - Node ID
	  @return 0 uif success, -1 if node does not exist or any error occured
	*/
	virtual Result_t Destroy(const BTreeNodeID_t & iNodeID)                       throw() = 0;

	/**
	  @brief Synchonize node to the hard disk
	  @param iNodeID - Node ID
	  @return 0 if success, -1 if node does not exist or any error occured
	*/
	virtual Result_t Sync(const BTreeNodeID_t & iNodeID)                          throw() = 0;

	/**
	  @brief Set debug level
	  @param iLevel - debug level
	*/
	virtual void Debug(const Level_t & iLevel)                                    throw() = 0;

	/** A destructor */
	virtual ~NodeStorage() throw() { ;; }
};

} // namespace FTSS
#endif // _NODE_STORAGE_HPP__
// End.
